/**
 * @author SilverBiology, LLC
 * @website http://code.google.com/p/gbif-spreadsheet-processor/
*/
Ext.namespace('GBIF');
Ext.namespace('GBIF.GeoSpatial')
	
GBIF.GeoSpatial.WFSCapabilitiesLayers = function(config){	
	var store;
	var sm = new Ext.grid.CheckboxSelectionModel({checkOnly: true}); 
	
	store = new GeoExt.data.WFSCapabilitiesStore({
		url: Config.General.Home.url + 'api/getcapabilities-proxy.php'
	});

	Ext.apply(this,config,{
			title: "WFS Capabilities"
		,	store: store
		,	sm: sm
		,	loadMask: true
		,	columns: [
					sm
				,	{header: "Title", dataIndex: "title", sortable: true}
				,	{header: "Name", dataIndex: "name", sortable: true}
				,	{header: "Value", dataIndex: "SRS", sortable: true}
			]
		,	tbar:[{
					text: 'Add Layer'
				,	scope: this
				,	ref: '../addlayer'
				,	handler: this.layerData
			}]	
		,	listeners: {
				rowcontextmenu: function(grid, index, e){
				indexI = index;
				if (!this.menu) {
					this.menu = new Ext.menu.Menu({
							id: 'menuId'
						,	items: [{
									text: 'Preview'
								, scope: this
								,	handler: function(){
										var rowdata = this.getSelectionModel().getSelections();
										this.getSelectionModel().selectRecords(rowdata);
										this.getSelectionModel().selectRow(indexI,true);
										this.fireEvent('showWin',rowdata,this);
									}
							}]
					});
					this.menu.on('hide', this.onContextHide, this);
				}
				e.stopEvent();
				this.menu.showAt(e.getXY());
			}
		}
 	});
	
	GBIF.GeoSpatial.WFSCapabilitiesLayers.superclass.constructor.call(this, config);

}

Ext.extend(GBIF.GeoSpatial.WFSCapabilitiesLayers,Ext.grid.GridPanel, {
	
	layerData: function(){
		if (this.getSelectionModel().getSelected()) {
			var rowdata = this.getSelectionModel().getSelected().data;
			this.fireEvent('addLayer', this,rowdata);
		}
	}
	
});